//
// Created by Tan Ke on 2024/1/18.
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

struct Item {
    int key;
    int val;
    struct Item* next;
};

struct ItemListHeader {
    int len;
    struct Item* next;
};
typedef struct {
    int capacity;
    struct ItemListHeader listHeader;
} LRUCache;


LRUCache* lRUCacheCreate(int capacity) {
    LRUCache* obj = (LRUCache*)malloc(sizeof(LRUCache));
    obj->capacity = capacity;
    obj->listHeader.len = 0;
    obj->listHeader.next = NULL;

    return obj;
}

int lRUCacheGet(LRUCache* obj, int key) {
    struct Item* prev = obj->listHeader.next;
    struct Item* tmp = obj->listHeader.next;
    while (tmp != NULL) {
        if (tmp->key == key) {
            break;
        }
        prev = tmp;
        tmp = tmp->next;
    }
    if (tmp != NULL) {
        prev->next = tmp->next;
        tmp->next = obj->listHeader.next;
        obj->listHeader.next = tmp;
        return tmp->val;
    } else {
        return -1;
    }
}

void lRUCachePut(LRUCache* obj, int key, int value) {
    struct Item* item = (struct Item*)malloc(sizeof(struct Item));
    item->key = key;
    item->val = value;
    item->next = obj->listHeader.next;
    obj->listHeader.next = item;
    obj->listHeader.len += 1;

}

void lRUCacheFree(LRUCache* obj) {

}

/**
 * Your LRUCache struct will be instantiated and called as such:
 * LRUCache* obj = lRUCacheCreate(capacity);
 * int param_1 = lRUCacheGet(obj, key);

 * lRUCachePut(obj, key, value);

 * lRUCacheFree(obj);
*/

int main(void)
{
    return 0;
}
